home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / Kamprath's CDEF Pack ƒ / CDEF Sampler Program ƒ / sampler.c < prev    next >
C/C++ Source or Header  |  1994-05-21  |  5KB  |  263 lines

  1. /*****
  2.  * bullseye.c
  3.  *
  4.  *    A simple demonstration program to play with the debugger
  5.  *
  6.  *
  7.  *****/
  8.  
  9. #include "samplerMenus.h"
  10. #include "samplerWindow.h"
  11. #include "samplerControls.h"
  12. #include "number_picker.h"
  13.  
  14. extern    WindowPtr        samplerWindow;
  15. extern    ControlHandle        rocketCntl, timeButtonCntl, timeCntl, dateCntl, numberCntl;
  16. extern    Rect            dragRect;
  17.  
  18. SysEnvRec    gMac;            
  19.  
  20. void InitMacintosh(void);
  21. void HandleMouseDown (EventRecord    *theEvent);
  22. void HandleEvent(void);
  23.  
  24. /****
  25.  * InitMacintosh()
  26.  *
  27.  * Initialize all the managers & memory
  28.  *
  29.  ****/
  30.  
  31. void InitMacintosh(void)
  32.  
  33. {
  34.     MaxApplZone();
  35.     
  36.     InitGraf(&thePort);
  37.     InitFonts();
  38.     FlushEvents(everyEvent, 0);
  39.     InitWindows();
  40.     InitMenus();
  41.     TEInit();
  42.     InitDialogs(0L);
  43.     InitCursor();
  44.  
  45.     SysEnvirons(curSysEnvVers, &gMac);
  46.     
  47.     if (gMac.systemVersion < 0x0700)
  48.         ExitToShell();
  49.  
  50. }
  51. /* end InitMacintosh */
  52.  
  53.  
  54. /****
  55.  * HandleMouseDown (theEvent)
  56.  *
  57.  *    Take care of mouseDown events.
  58.  *
  59.  ****/
  60.  
  61. void HandleMouseDown (EventRecord    *theEvent)
  62.  
  63. {
  64.     WindowPtr    theWindow;
  65.     int            windowCode = FindWindow (theEvent->where, &theWindow);
  66.     
  67.     switch (windowCode)
  68.       {
  69.       case inSysWindow: 
  70.         SystemClick (theEvent, theWindow);
  71.         break;
  72.         
  73.       case inMenuBar:
  74.           AdjustMenus();
  75.         HandleMenu(MenuSelect(theEvent->where));
  76.         break;
  77.         
  78.       case inDrag:
  79.           if (theWindow == samplerWindow)
  80.             DragWindow(samplerWindow, theEvent->where, &dragRect);
  81.             break;
  82.             
  83.       case inContent:
  84.           if (theWindow == samplerWindow)
  85.           {
  86.           short            cntlPart;
  87.           Point            clickPt = theEvent->where;
  88.           ControlHandle    foundCntl;
  89.           
  90.               if (theWindow != FrontWindow())
  91.                   SelectWindow(samplerWindow);
  92.                 else
  93.                 {
  94.                     GlobalToLocal(&clickPt);
  95.                     
  96.                   cntlPart = FindControl(clickPt, samplerWindow, &foundCntl);
  97.                   if (cntlPart)
  98.                   {
  99.                       if (( foundCntl == rocketCntl)||( foundCntl == timeButtonCntl ))
  100.                       {
  101.                           if (cntlPart = TrackControl( foundCntl, clickPt, 0 ))
  102.                           {
  103.                               if ( foundCntl == rocketCntl)
  104.                               {
  105.                                   SysBeep(20);
  106.                               }
  107.                               else if (foundCntl == timeButtonCntl)
  108.                               {
  109.                                   SetCtlValue( timeButtonCntl, !GetCtlValue(timeButtonCntl));
  110.  
  111.                                 if (GetCtlValue( timeButtonCntl))
  112.                                 {
  113.                                     HiliteControl(timeCntl, 0);
  114.                                     HiliteControl(dateCntl, 0);
  115.                                     HiliteControl(numberCntl, 0);
  116.                                 }
  117.                                 else
  118.                                 {
  119.                                     HiliteControl(timeCntl, 255);
  120.                                     HiliteControl(dateCntl, 255);
  121.                                     HiliteControl(numberCntl, 255);
  122.                                 }
  123.  
  124.                               }
  125.                           }
  126.                       }
  127.                       else
  128.                       {
  129.                           if ( foundCntl == dateCntl)
  130.                           {
  131.                               SetCtlValue( timeCntl, 0 );
  132.                               HandleDateCDEFClick(clickPt);
  133.                           }
  134.                           else if ( foundCntl == timeCntl)
  135.                           {
  136.                               SetCtlValue( dateCntl, 0 );
  137.                               HandleTimeCDEFClick(clickPt);
  138.                           }
  139.                           else if ( foundCntl == numberCntl)
  140.                           {
  141.                               if (cntlPart = TrackControl( foundCntl, clickPt, NumCDEFProc ))
  142.                               {
  143.                                 /* do nothing because NumCDEFProc() handles it */
  144.                               }
  145.                           }
  146.                       }
  147.                   }
  148.                   else
  149.                   {
  150.                       SetCtlValue( timeCntl, 0 );
  151.                       SetCtlValue( dateCntl, 0 );
  152.                   }
  153.               }
  154.                               
  155.                   
  156.            }
  157.           break;
  158.           
  159.       case inGoAway:
  160.           if (theWindow == samplerWindow && 
  161.               TrackGoAway(samplerWindow, theEvent->where))
  162.           HideWindow(samplerWindow);
  163.             break;
  164.       }
  165. }
  166. /* end HandleMouseDown */
  167.  
  168.  
  169. /****
  170.  * HandleEvent()
  171.  *
  172.  *        The main event dispatcher. This routine should be called
  173.  *        repeatedly (it  handles only one event).
  174.  *
  175.  *****/
  176.  
  177. void HandleEvent(void)
  178.  
  179. {
  180.     int                ok;
  181.     EventRecord        theEvent;
  182.     ControlHandle    curCntl;
  183.  
  184.     HiliteMenu(0);
  185.     SystemTask ();        /* Handle desk accessories */
  186.     
  187.     ok = GetNextEvent (everyEvent, &theEvent);
  188.     if (ok)
  189.         switch (theEvent.what)
  190.         {
  191.             case mouseDown:
  192.                 HandleMouseDown(&theEvent);
  193.                 break;
  194.             
  195.             case keyDown: 
  196.             case autoKey:
  197.                 if ((theEvent.modifiers & cmdKey) != 0)
  198.                 {
  199.                       AdjustMenus();
  200.                       HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
  201.                   }
  202.                 break;
  203.             
  204.             case updateEvt:
  205.                 BeginUpdate(samplerWindow);
  206.                 DrawSampleWindow(((WindowPeek) samplerWindow)->hilited);
  207.                 EndUpdate(samplerWindow);
  208.                 break;
  209.             
  210.             case activateEvt:
  211.                 if (theEvent.modifiers & activeFlag)
  212.                 {
  213.                     HiliteControl(rocketCntl, 0);
  214.                     HiliteControl(timeButtonCntl, 0);
  215.                     
  216.                     if (GetCtlValue( timeButtonCntl))
  217.                     {
  218.                         HiliteControl(timeCntl, 0);
  219.                         HiliteControl(dateCntl, 0);
  220.                         HiliteControl(numberCntl, 0);
  221.                     }
  222.                     else
  223.                     {
  224.                         HiliteControl(timeCntl, 255);
  225.                         HiliteControl(dateCntl, 255);
  226.                         HiliteControl(numberCntl, 255);
  227.                     }
  228.                         
  229.                 }
  230.                 else
  231.                 {    
  232.                     curCntl = ((WindowPeek)samplerWindow)->controlList;
  233.                     while (curCntl)
  234.                     {
  235.                         HiliteControl(curCntl, 255);
  236.                         curCntl = (*curCntl)->nextControl;
  237.                     }
  238.                 }
  239.                 break;
  240.         }
  241. }
  242. /* end HandleEvent */
  243.  
  244.  
  245. /*****
  246.  * main()
  247.  *
  248.  *    This is where everything happens
  249.  *
  250.  *****/
  251.  
  252.  
  253. main()
  254.  
  255. {
  256.     InitMacintosh();
  257.     SetUpMenus();
  258.     SetUpWindow();
  259.     
  260.     for (;;)
  261.         HandleEvent();
  262. }
  263. /* end main */